<template>
  <div class="head">
    <div class="container">
      <div class="left">
        <img
          src="~/assets/images/logo1.png"
          alt=""
          style="cursor:pointer;"
          @click="toHome"
        />
      </div>
      <div class="search">
        <div class="tabs">
          <div @click="current = 0" :class="current === 0 ? 'filled' : 'bordered'"  class="tabItem">找包装</div>
          <div @click="current = 1" :class="current === 1 ? 'filled' : 'bordered'" class="tabItem">找服务</div>
          <div @click="current = 2" :class="current === 2 ? 'filled' : 'bordered'" class="tabItem">找企业</div>
        </div>
        <m-searchbar
          width="400px"
          v-model.trim="keywords"
          placeholder="请输入关键词搜索"
          @click-search="search"
        />
        <div class="words mtp10">
          <span
            class="wordItem f14 cor999"
            v-for="(item, index) in tabMain[current]"
            :key="index"
            @click="goSearch(item.txt)"
            >{{ item.txt }}</span
          >
        </div>
      </div>
      <div class="right">
        <div class="into">
          <router-link to="/home/businessSettlement">
            <span>商家免费入驻</span>
            <div class="into-icon">
              <img src="~/assets/images/icon.png" alt="" />
            </div>
          </router-link>
        </div>
        <div class="icon">
          <router-link to="/profile">
            <div class='person_icon'/>
            <span>个人中心</span>
          </router-link>
          <router-link to="/profile/message-management/my-message">
            <div class='news_icon'/>
            <span>我的消息</span>
          </router-link>
          <router-link to="/cart">
            <div class='cart_icon'/>
            <span>购物车</span>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import MSearchbar from "@/components/m-searchbar/MSearchbar"
import MButton from "@/components/common/m-button/MButton"

export default {
  name: "Head",
  components: { MButton, MSearchbar },
  data() {
    return {
      tabTitle: ["找包装", "找服务", "找企业"],
      tabMain: [
        [{ txt: "塑料瓶" }, { txt: "玻璃容器" }],
        [{ txt: "塑料瓶222" }, { txt: "玻璃容器" }],
        [{ txt: "塑料瓶333" }, { txt: "玻璃容器" }]
      ],
      current: 0,
      keywords: ""
    }
  },
  methods: {
    toHome() {
      this.$router.push({ path: "/", query: { t: Date.now() } })
    },
    goSearch(keyword) {
      this.keywords = keyword
      this.search()
    },
    search() {
      if (!this.keywords) {
        return this.$toastVant("请输入关键词！")
      }
      const title = this.tabTitle[this.current]
      if (title === "找包装") {
        this.$router.push({
          name: "SearchPackage",
          params: {
            keyword: this.keywords
          },
          query: {
            type: 1,
            t: Date.now()
          }
        })
      } else if (title === "找服务") {
        this.$router.push({
          name: "SearchPackage",
          params: {
            keyword: this.keywords
          },
          query: {
            type: 0,
            t: Date.now()
          }
        })
      } else if (title === "找企业") {
        this.$router.push({
          name: "SearchCompany",
          params: {
            keyword: this.keywords
          },
          query: {
            t: Date.now()
          }
        })
      }
    },
    // 切换移入移出时图片状态
    changeImageSrc(key) {
      switch (key) {
        case 1:
          this.staImg1 = require(`@/assets/images/home/person_h.png`)
          break;
        case 2:
          this.staImg2 = require(`@/assets/images/home/news_h.png`)
          break;
        case 3:
          this.staImg1 = require(`@/assets/images/home/cart_h.png`)
          break;
        //可以继续添加
      }
    }
  }
}
</script>

<style scoped>
.filled {
  background-color: #e48b2c;
  color: #fff;
}

.bordered {
  background-color: #fff;
  border: solid 1px #ccc;
}

.head .left {
  padding-top: 50px;
  padding-right: 116px;
  padding-bottom: 50px;
  box-sizing: border-box;
}

.head .left img {
  width: 259px;
}

.head .search {
  float: left;
  padding-top: 30px;
  box-sizing: border-box;
}

.head .search .words {
  display: flex;
}

.head .search .wordItem {
  display: inline-block;
  cursor: pointer;
  margin-right: 10px;
}

.head .search .wordItem:hover {
  color: #e48b2c;
}

.head .search .tabs {
  display: flex;
  margin-bottom: 15px;
}

.head .search .tabs .tabItem {
  border-color: #e48b2c;
  width: 82px;
  height: 35px;
  line-height: 34px;
  text-align: center;
  font-size: 14px;
  border-radius: 15px;
  margin-right: 10px;
  cursor: pointer;
}

.search .sea-top a {
  padding: 10px 20px;
  border-radius: 14px;
  border: 1px solid #f0f0f0;
  margin-left: 6px;
}

.search .sea-top a:nth-child(1) {
  margin-left: 0;
}

.search .sea-top a.active {
  color: #fff;
  background: #e38b2e;
  border: 1px solid #e38b2e;
}

.sea-box {
  font-size: 16px;
  margin-top: 15px;
  width: 413px;
  height: 45px;
  line-height: 45px;
  border-radius: 19px;
  border: 2px solid #f0f0f0;
  padding-left: 11px;
  position: relative;
}

.sea-box img {
  position: absolute;
  top: 15px;
  left: 16px;
  width: 19px;
  height: 19px;
}

.sea-box .sear-input {
  height: 37px;
  line-height: 37px;
  width: 352px;
  padding-left: 36px;
}

.sea-box .sear-btn {
  position: absolute;
  top: -2px;
  right: -1px;
  width: 84px;
  height: 45px;
  text-align: center;
  line-height: 45px;
  color: #fff;
  background: #e38b2e;
  border-top-right-radius: 19px;
  border-bottom-right-radius: 19px;
}

.sea-bottom {
  margin-top: 9px;
  color: #e38b2e;
}

.sea-bottom a {
  margin-left: 17px;
}

.head .right {
  padding-top: 32px;
}

.into {
  width: 252px;
  height: 50px;
  font-size: 20px;
  font-weight: bold;
  line-height: 50px;
  color: #fff;
  background: #0085e8;
  border-radius: 24.72px;
  position: relative;
  margin-bottom: 25px;
}

.into a {
  display: block;
  width: 100%;
  padding-left: 40px;
}

.into .into-icon {
  position: absolute;
  top: 0;
  right: 0;
  width: 30px;
  height: 50px;
  background: #e38b2e;
  border-top-right-radius: 24.72px;
  border-bottom-right-radius: 24.72px;
}

.into .into-icon::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -15px;
  transform: translateY(-50%);
  width: 29px;
  height: 29px;
  border-radius: 50%;
  background-color: #e38b2e;
}

.into .into-icon img {
  width: 20px;
  height: 23px;
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.icon {
  display: flex;
}

.icon a {
  flex: 1;
  display: flex;
  flex-direction: column;
  text-align: center;
  justify-content: center;
  align-items: center;
}

.icon a.active {
  color: #e38b2e;
}

.icon a:hover {
  color: #e38b2e;
}

.icon .person_icon {
  width: 20px;
  height: 21px;
  margin-bottom: 6px;
  background: url('~@/assets/images/home/person.png')
}
.icon .person_icon:hover {
  background: url('~@/assets/images/home/person_h.png');
  color: #e48b2c;
}
.icon .news_icon {
  width: 20px;
  height: 21px;
  margin-bottom: 6px;
  background: url('~@/assets/images/home/news.png')
}
.icon .news_icon:hover {
  background: url('~@/assets/images/home/news_h.png');
  color: #e48b2c;
}
.icon .cart_icon {
  width: 20px;
  height: 21px;
  margin-bottom: 6px;
  background: url('~@/assets/images/home/cart.png')
}
.icon .cart_icon:hover {
  background: url('~@/assets/images/home/cart_h.png');
  color: #e48b2c;
}

.icon a img {
  margin-bottom: 6px;
}

@media only screen and (max-width: 1200px) {
  .head .left {
    padding-right: 120px;
  }
}

.gold1:hover {
  color: #e48b2c;
}

.gold2:hover {
  color: #e48b2c;
}
</style>
